package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.Hotel;
import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.query.HotelQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IHotelService;
import cn.wolfcode.trip.base.util.UploadUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;


@Controller
@RequestMapping("/hotel")
public class HotelController {
    @Autowired
    private IHotelService service;

    @RequestMapping("/list")
    public String  list(@ModelAttribute("qo") HotelQueryObject qo, Model model){
        PageInfo info = service.query(qo);
        model.addAttribute("info",info);
        return "/hotel/list";
    }

    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(Hotel hotel, MultipartFile file){
        if ((!file.isEmpty()) && file.getSize() > 0) {
            String url = UploadUtil.upload(file);
            hotel.setCoverUrl(url);
        }
        service.saveOrUpdate(hotel);
        return "redirect:/hotel/list.do";
    }



}
